package com.iafme.controller;

import cn.hutool.core.convert.Convert;
import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.iafme.dto.req.InformationEmailReqDTO;
import com.iafme.dto.req.InformationReqDTO;
import com.iafme.dto.res.InformationResDTO;
import com.iafme.service.InformationService;
import com.systemframework.common.BaseCommonInterface;
import com.systemframework.constants.Constants;
import com.systemframework.upload.FileUploadConfig;
import com.systemframework.util.Result;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.validation.Valid;
import java.util.List;

/**
 * @author summer
 * @version 1.0
 * @date 2025/3/23 14:15
 */
@RestController
@RequestMapping(value = "/information")
@AllArgsConstructor
@Slf4j
public class InformationController implements BaseCommonInterface<InformationReqDTO, InformationResDTO> {

    private final InformationService informationService;

    @Override
    public Result<String> save(@Valid InformationReqDTO informationReqDTO) {
        return null;
    }

    @Override
    public Result<String> update(@Valid InformationReqDTO informationReqDTO) {
        return null;
    }

    @Override
    public Result<String> del(Integer integer) {
        return null;
    }

    @Override
    public Result<Page<InformationResDTO>> lists(InformationReqDTO informationReqDTO) {

        return Result.successResult(informationService.lists(informationReqDTO));
    }

    @Override
    public Result<InformationResDTO> findById(Integer integer) {
        return null;
    }

    @Override
    public Result<String> batchDel(List<InformationResDTO> list) {
        return null;
    }

    @GetMapping(value = "/findList")
    public List<InformationResDTO> findList(){
        return Convert.toList(InformationResDTO.class,informationService.list());
    }

    @PostMapping(value = "/sendEmail")
    public String sendEmail(@RequestBody InformationEmailReqDTO emailReqDTO){
        log.info("emailReqDTO:{}", JSON.toJSONString(emailReqDTO));
        informationService.sendEmail(emailReqDTO);
        return Constants.SUCESS;
    }

    private final FileUploadConfig fileUploadConfig;

    @PostMapping(value = "/uploadFile")
    public Result<String> uploadFile(MultipartFile file){

        return Result.successResult(fileUploadConfig.upload(file));
    }
}
